package cn.stylefeng.guns.modular.storage.controller;

import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.core.util.QRCodeUtil;
import cn.stylefeng.guns.modular.basic.entity.BasicGoods;
import cn.stylefeng.guns.modular.basic.model.params.BasicPositionParam;
import cn.stylefeng.guns.modular.basic.model.params.BasicTrayParam;
import cn.stylefeng.guns.modular.basic.model.result.BasicPositionResult;
import cn.stylefeng.guns.modular.basic.model.result.BasicTrayResult;
import cn.stylefeng.guns.modular.basic.service.BasicGoodsService;
import cn.stylefeng.guns.modular.basic.service.BasicPositionService;
import cn.stylefeng.guns.modular.basic.service.BasicTrayService;
import cn.stylefeng.guns.modular.basic.service.BasicWarehouseService;
import cn.stylefeng.guns.modular.storage.entity.StoragePutSingle;
import cn.stylefeng.guns.modular.storage.model.params.StorageOutDetailedParam;
import cn.stylefeng.guns.modular.storage.model.params.StoragePutParam;
import cn.stylefeng.guns.modular.storage.model.params.StoragePutSingleParam;
import cn.stylefeng.guns.modular.storage.model.params.StorageStockParam;
import cn.stylefeng.guns.modular.storage.model.result.StoragePutResult;
import cn.stylefeng.guns.modular.storage.model.result.StoragePutSingleResult;
import cn.stylefeng.guns.modular.storage.service.StorageOutDetailedService;
import cn.stylefeng.guns.modular.storage.service.StoragePutService;
import cn.stylefeng.guns.modular.storage.service.StoragePutSingleService;
import cn.stylefeng.guns.modular.storage.service.StorageStockService;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.guns.sys.modular.system.service.UserService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;


/**
 * 入库单明细表控制器
 */
@Controller
@RequestMapping("/storagePutSingle")
public class StoragePutSingleController extends BaseController {

    private String PREFIX = "/storage/storagePutSingle";

    @Autowired
    private StoragePutSingleService storagePutSingleService;

    @Autowired
    private UserService userService;

    @Autowired
    private BasicGoodsService basicGoodsService;

    @Autowired
    private BasicTrayService basicTrayService;

    @Autowired
    private StoragePutService storagePutService;

    @Autowired
    private BasicPositionService basicPositionService;

    @Autowired
    private StorageStockService storageStockService;

    @Autowired
    private BasicWarehouseService basicWarehouseService;

    private Lock lock = new ReentrantLock();

    /**
     * 去批量打印页面
     */
    @RequestMapping("/tobtnqrCode")
    public String tobtnqrCode() {
        return PREFIX + "/btnqrCode.html";
    }

    /**
     * 创建二维码
     */
    @RequestMapping(value = "/getqrcode", method = RequestMethod.GET)
    @ResponseBody
    public void generateQRCode4Product(String id,String name, HttpServletRequest request, HttpServletResponse response) {
        try {
            //logo
            File logoFile = new File("");
            String url = id;
            QRCodeUtil.drawLogoQRCode(logoFile, url, name,200,180,request,response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 跳转到入库记录
     */
    @RequestMapping("rukujilu")
    public String rukujilu(Model model) {
    	User user = userService.getcurrentUser();
    	Long deptId = userService.getDeptId();
    	Long deliverId = userService.getDeliverId();
    	model.addAttribute("basicWarehouseList", basicWarehouseService.findAvailableList(deptId,deliverId,user.getOperateId()));
//    	model.addAttribute("startSingleTime",DateUtil.getPastDate(7));
//    	model.addAttribute("endSinglePutTime",DateUtil.getDate());
        return PREFIX + "/putjilu.html";
    }

    /**
     * 查询列表
     */
    @ResponseBody
    @RequestMapping("/putjilu")
    public LayuiPageInfo putjilu(StoragePutSingleParam storagePutSingleParam,String condition ,Long warehouseId,String startSingleTime,String endSinglePutTime) {
    	if (ToolUtil.isNotEmpty(startSingleTime) && ToolUtil.isNotEmpty(endSinglePutTime)) {
    		storagePutSingleParam.setNodes("'"+startSingleTime+"' and '"+endSinglePutTime+"'");
		}
//    	if (startSingleTime == null && endSinglePutTime == null) {
//    		storagePutSingleParam.setNodes("'"+DateUtil.getPastDate(7)+"' and '"+DateUtil.getDate()+"'");
//		}
    	User user = userService.getcurrentUser();
    	Long deptId = user.getDeptId();
    	Long deliverId = user.getDeliverId();
        return this.storagePutSingleService.findPageBySpecjilu(storagePutSingleParam,condition,warehouseId,deptId,deliverId,user.getOperateId());
    }

    /**
     * 导出Excel
     */
    @RequestMapping("/exportExcelBySpec")
    public void exportExcelBySpec(HttpServletResponse response, StoragePutSingleParam storagePutSingleParam,String condition2 ,Long warehouseId,String startSingleTime,String endSinglePutTime) throws IOException {
    	if (ToolUtil.isNotEmpty(startSingleTime) && ToolUtil.isNotEmpty(endSinglePutTime)) {
    		storagePutSingleParam.setNodes("'"+startSingleTime+"' and '"+endSinglePutTime+"'");
		}
    	storagePutSingleParam.setWarehouseId(warehouseId);
    	storagePutSingleParam.setCondition2(condition2);
        Workbook wb = storagePutSingleService.exportToExcel(storagePutSingleParam);
        OutputStream output = response.getOutputStream();
        response.setContentType("application/vnd.ms-excel;charset=utf-8");
        response.setHeader("Content-Disposition", "attachment;filename=" + new String(("Storage record information" + ".xlsx").getBytes(), "iso-8859-1"));
        wb.write(output);
        output.close();
    }

    /**
     * 跳转到主页面
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/storagePutSingle.html";
    }

    /**
     * 入库单查询打印出使用
     */
    @RequestMapping("print")
    public String print(StoragePutSingleParam storagePutSingleParam, Model model) {
        model.addAttribute("storagePutSingleParam", storagePutSingleParam);
        return PREFIX + "/putSinglePrint.html";
    }

    /**
     * 新增页面
     */
    @RequestMapping("/add")
    public String add(@RequestParam("storageNumber")String storageNumber,
    		@RequestParam("goodsId")Long goodsId,Model model) {
    	BasicGoods basicGoods = basicGoodsService.getById(goodsId);
    	model.addAttribute("storageNumber", storageNumber);
    	model.addAttribute("basicGoods", basicGoods);
        return PREFIX + "/storagePutSingle_add.html";
    }


    /**
     * 新增页面
     */
    @RequestMapping("/appaddbatch")
    public String appaddbatch(@RequestParam("storageNumber")String storageNumber,
                      @RequestParam("goodsId")Long goodsId,Model model) {
        BasicGoods basicGoods = basicGoodsService.getById(goodsId);
        model.addAttribute("storageNumber", storageNumber);
        model.addAttribute("basicGoods", basicGoods);
        return PREFIX + "/storagePutSingle_add.html";
    }

    /**
     * 编辑页面
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/storagePutSingle_edit.html";
    }

    /**
     * 选择库位页面
     */
    @RequestMapping("/toChoiceposition")
    public String toChoiceposition(@RequestParam("storageNumber")String storageNumber,Model model) {
    	model.addAttribute("storageNumber", storageNumber);
        return PREFIX + "/choiceposition.html";
    }

    /**
     * 库存监控选择库位页面
     */
    @RequestMapping("/toPositionStock")
    public String toPositionStock(@RequestParam("positionAreaId")Long positionAreaId,@RequestParam("warehouseId")Long warehouseId,Model model) {
    	model.addAttribute("positionAreaId", positionAreaId);
    	model.addAttribute("warehouseId", warehouseId);
        return PREFIX + "/positionStock.html";
    }


    /**
     * 批量选择库位页面
     */
    @RequestMapping("/toPointsPosition")
    public String toPointsPosition() {
        return PREFIX + "/pointsPosition.html";
    }


    /**
     * 批量选择库位页面
     */
    @RequestMapping("/toPointsPosition2")
    public String toPointsPosition2() {
        return PREFIX + "/pointsPosition2.html";
    }

    /**
     * 新增批次接口
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(StoragePutSingleParam storagePutSingleParam) {
    	String goodsname = storagePutSingleParam.getGoodsname();
    	//解决参数中的 英文括号
    	if (goodsname!=null&&goodsname!="") {
    		goodsname = goodsname.replace("& #40;", "(");
    		goodsname = goodsname.replace("& #41;", ")");
    		storagePutSingleParam.setGoodsname(goodsname);
    	}
		lock.lock();//获取锁
		try {
	        this.storagePutSingleService.increase(storagePutSingleParam);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			lock.unlock();//释放锁
		}
        return ResponseData.success();
    }


    /**
     * app新增批次接口
     */
    @RequestMapping("/appaddItem")
    @ResponseBody
    public ResponseData appaddItem(StoragePutSingleParam storagePutSingleParam) {
        Long goodsId = storagePutSingleParam.getGoodsId();
        BasicGoods basicGoods = basicGoodsService.getById(goodsId);

        BigDecimal v = new BigDecimal(basicGoods.getGoodsVolume());//体积

        BigDecimal putNum = new BigDecimal(storagePutSingleParam.getPutNum());//数量
        BigDecimal u = new BigDecimal(storagePutSingleParam.getUnitprice());//单价

        BigDecimal w = new BigDecimal(basicGoods.getGoodsWeight());//重量

        storagePutSingleParam.setSingleRebubbles( basicGoods.getGoodsHeavybubble());//singleRebubbles  重泡货
        storagePutSingleParam.setSinglePacking(basicGoods.getGoodsPacking());//singlePacking  商品包装
        storagePutSingleParam.setSingleLargeclass(basicGoods.getGoodsBigtype());//singleLargeclass 商品大类
        storagePutSingleParam.setSingleGoodstype(basicGoods.getGoodsType());//singleGoodstype 商品类别
        storagePutSingleParam.setSinglePutcondition(basicGoods.getGoodsCondition());//singlePutcondition 保管条件
        storagePutSingleParam.setGoodsname(basicGoods.getGoodsName());//商品名称
        storagePutSingleParam.setGoodsNumber( basicGoods.getGoodsNumber());//商品编号
        storagePutSingleParam.setDetailedPutvolume((putNum.multiply(v)).toString());//应入体积
        storagePutSingleParam.setPutWeight((putNum.multiply(w)).toString());//应入重量
        storagePutSingleParam.setPutBalenum(storagePutSingleParam.getPutNum());//入大包数
        storagePutSingleParam.setSingleMoney((putNum.multiply(u)).toString());//应入金额
        storagePutSingleParam.getUnitprice();//单价
        storagePutSingleParam.setSinglePiecenum("1");

		lock.lock();//获取锁
		try {
	        this.storagePutSingleService.increase(storagePutSingleParam);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			lock.unlock();//释放锁
		}
        return ResponseData.success();
    }

    /**
     * 编辑接口
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(StoragePutSingleParam storagePutSingleParam) {
    	StoragePutSingle s = storagePutSingleService.getById(storagePutSingleParam.getId());
    	s.setPositionNumber(storagePutSingleParam.getPositionNumber());//库位编号
    	s.setPutBalenum(storagePutSingleParam.getPutBalenum());//应入大包数
    	s.setPutNum(storagePutSingleParam.getPutNum());//应入数量
    	s.setSingleDateofmanufacture(storagePutSingleParam.getSingleDateofmanufacture());
    	s.setSingleBatchnumber(storagePutSingleParam.getSingleBatchnumber());//批号
    	s.setRecommend(storagePutSingleParam.getRecommend());

        BigDecimal putNum = new BigDecimal(storagePutSingleParam.getPutNum());//数量
        BigDecimal w = new BigDecimal(s.getGoodsWeight());//重量
        BigDecimal v = new BigDecimal(s.getGoodsVolume());//体积
        BigDecimal u = new BigDecimal(s.getUnitprice());//体积
		s.setPutWeight((putNum.multiply(w)).toString());//应入重量
		s.setDetailedPutvolume((putNum.multiply(v)).toString());//应入体积
		s.setSingleMoney((putNum.multiply(u)).toString());//应入金额
		StoragePutSingleParam p = new StoragePutSingleParam();
        ToolUtil.copyProperties(s,p);
        this.storagePutSingleService.update(p);
        return ResponseData.success();
    }


    /**
     * app修改托盘数量接口
     */
    @RequestMapping("/appeditItem")
    @ResponseBody
    public ResponseData appeditItem(StoragePutSingleParam storagePutSingleParam) {
        StoragePutSingleParam p = new StoragePutSingleParam();
        StoragePutSingle s = storagePutSingleService.getById(storagePutSingleParam.getId());//托盘信息
        ToolUtil.copyProperties(s,p);
        p.setPutBalenum(storagePutSingleParam.getPutNum());//应入大包数
        p.setPutNum(storagePutSingleParam.getPutNum());//应入数量


        BigDecimal putNum = new BigDecimal(storagePutSingleParam.getPutNum());//数量
        BigDecimal w = new BigDecimal(p.getGoodsWeight());//重量
        BigDecimal v = new BigDecimal(p.getGoodsVolume());//体积
        BigDecimal u = new BigDecimal(p.getUnitprice());//体积

        p.setPutWeight(String.valueOf(w.multiply(putNum)));//应入重量
        p.setDetailedPutvolume( String.valueOf(v.multiply(putNum)));//应入体积
        p.setSingleMoney( String.valueOf(u.multiply(putNum)));//应入金额
        this.storagePutSingleService.update(p);
        return ResponseData.success();
    }

    /**
     * 删除接口
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(StoragePutSingleParam storagePutSingleParam) {
    	User user = userService.getcurrentUser();
    	StoragePutSingle storagePutSingle = storagePutSingleService.getById(storagePutSingleParam.getId());
    	BasicTrayParam bParam =  new BasicTrayParam();
    	bParam.setTrayNumber(storagePutSingle.getTrayNumber());
    	bParam.setDeptId(user.getDeptId());
    	BasicTrayResult bResult =  basicTrayService.findBySpec(bParam,user.getOperateId());
    	bResult.setTrayState("IDLE");
        ToolUtil.copyProperties(bResult,bParam);
    	basicTrayService.update(bParam);
        this.storagePutSingleService.delete(storagePutSingleParam);
        return ResponseData.success();
    }

    /**
     * 删除批次接口
     */
    @RequestMapping("/deleteBatch")
    @ResponseBody
	@Transactional(rollbackFor = Exception.class)
    public ResponseData deleteBatch(StoragePutSingleParam storagePutSingleParam) {
    	List<BasicTrayParam> tList = new ArrayList<BasicTrayParam>();
    	List<Integer> pList = new ArrayList<Integer>();
    	BasicTrayParam tP = new BasicTrayParam();

    	storagePutSingleParam.setSingleState("NOT_STARTED");
    	List<StoragePutSingleResult> sprlist  = storagePutSingleService.findListBySpec(storagePutSingleParam);
    	for (StoragePutSingleResult spR : sprlist) {
    		pList.add(spR.getId());
    		tP.setTrayNumber(spR.getTrayNumber());
    		tP.setTrayState("IDLE");
    		tList.add(tP);
    		tP = new BasicTrayParam();
		}
    	if (tList.size()>0&&pList.size()>0) {
    		storagePutSingleService.batchDelete(pList);
    		basicTrayService.batchupdate(tList);
		}
        return ResponseData.success();
    }

    /**
     * 删除批次接口
     */
    @RequestMapping("/appdeleteBatch")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public ResponseData appdeleteBatch(StoragePutSingleParam storagePutSingleParam) {
        List<BasicTrayParam> tList = new ArrayList<BasicTrayParam>();
        List<Integer> pList = new ArrayList<Integer>();
        BasicTrayParam tP = new BasicTrayParam();

        storagePutSingleParam.setSingleState("NOT_STARTED");
        List<StoragePutSingleResult> sprlist  = storagePutSingleService.findListBySpec(storagePutSingleParam);
        for (StoragePutSingleResult spR : sprlist) {
            pList.add(spR.getId());
            tP.setTrayNumber(spR.getTrayNumber());
            tP.setTrayState("IDLE");
            tList.add(tP);
            tP = new BasicTrayParam();
        }
        if (tList.size()>0&&pList.size()>0) {
            storagePutSingleService.batchDelete(pList);
            basicTrayService.batchupdate(tList);
        }
        return ResponseData.success();
    }

    /**
     * app删除托盘接口
     */
    @RequestMapping("/appdelete")
    @ResponseBody
    public ResponseData appdelete(StoragePutSingleParam storagePutSingleParam) {
    	User user = userService.getcurrentUser();
    	StoragePutSingle storagePutSingle = storagePutSingleService.getById(storagePutSingleParam.getId());
        BasicTrayParam bParam =  new BasicTrayParam();
        bParam.setTrayNumber(storagePutSingle.getTrayNumber());
        bParam.setDeptId(user.getDeptId());
        BasicTrayResult bResult =  basicTrayService.findBySpec(bParam,user.getOperateId());
        bResult.setTrayState("IDLE");
        ToolUtil.copyProperties(bResult,bParam);
        basicTrayService.update(bParam);
        this.storagePutSingleService.delete(storagePutSingleParam);
        return ResponseData.success();
    }

    /**
     * 批量开始入库
     */
    @RequestMapping("/startGoods")
    @ResponseBody
	@Transactional(rollbackFor = Exception.class,timeout=80)
    public ResponseData startGoods(@RequestParam("goodsIds") Long[] goodsIds,@RequestParam("storageNumber") String storageNumber) {
    	for (Long goodsId :goodsIds) {
    		StoragePutSingleParam sParam = new StoragePutSingleParam();
    		sParam.setGoodsId(goodsId);
    		sParam.setStorageNumber(storageNumber);
    		sParam.setSingleState("NOT_STARTED");
    		List<StoragePutSingleResult> list =  storagePutSingleService.findListBySpec(sParam);
    		List<StoragePutSingle> ulist =  new ArrayList<StoragePutSingle>();
    		for (StoragePutSingleResult sResult : list) {
    			if (sResult.getPositionNumber()==null) {
    				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚失误
    				ResponseData rData = new ResponseData();
    				rData.setSuccess(false);
    				rData.setMessage("No storage location assigned; unable to start");
    				return rData;
				}
    			StoragePutSingle ss = new StoragePutSingle();
    			sResult.setSingleState("NOT_RECEIVED");
    	        ToolUtil.copyProperties(sResult,ss);
    	        ulist.add(ss);
    	        ss = new StoragePutSingle();
			}
    		storageStockService.batchAdd(ulist);//新增库存
    		storagePutSingleService.updateBatchList(ulist);
    		ulist = new ArrayList<StoragePutSingle>();
		}
        return ResponseData.success();
    }


    /**
     * app开始入库
     */
    @RequestMapping("/appstartGoods")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public ResponseData appstartGoods(@RequestParam("goodsIds") Long goodsId,@RequestParam("storageNumber") String storageNumber) {
            StoragePutSingleParam sParam = new StoragePutSingleParam();
            sParam.setGoodsId(goodsId);
            sParam.setStorageNumber(storageNumber);
            sParam.setSingleState("NOT_STARTED");
            List<StoragePutSingleResult> list =  storagePutSingleService.findListBySpec(sParam);
            if(list==null && list.isEmpty()){
                ResponseData rData = new ResponseData();
                rData.setSuccess(false);
                rData.setMessage("This commodity has started inbound processing.");
                return rData;
            }
            List<StoragePutSingle> ulist =  new ArrayList<StoragePutSingle>();
            for (StoragePutSingleResult sResult : list) {
                if (sResult.getPositionNumber()==null) {
                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚失误
                    ResponseData rData = new ResponseData();
                    rData.setSuccess(false);
                    rData.setMessage("No storage location assigned; unable to start");
                    return rData;
                }
                StoragePutSingle ss = new StoragePutSingle();
                sResult.setSingleState("NOT_RECEIVED");
                ToolUtil.copyProperties(sResult,ss);
                ulist.add(ss);
    	        ss = new StoragePutSingle();
            }
    		storageStockService.batchAdd(ulist);//新增库存
            storagePutSingleService.updateBatchList(ulist);
    		ulist = new ArrayList<StoragePutSingle>();
        return ResponseData.success();
    }

    /**
     * 批量分配库位
     */
    @RequestMapping("/pointsPosition")
    @ResponseBody
	@Transactional(rollbackFor = Exception.class)
    public ResponseData pointsPosition(Long[] ids,String positionNumber) {
        List<StoragePutSingle> ulist =  new ArrayList<StoragePutSingle>();
    	for (Long id :ids) {
    		StoragePutSingle storagePutSingle = storagePutSingleService.getById(id);
    		storagePutSingle.setPositionNumber(positionNumber);
    		ulist.add(storagePutSingle);
		}
        storagePutSingleService.updateBatchList(ulist);
        return ResponseData.success();
    }

    /**
     * app批量分配库位
     */
    @RequestMapping("/apppointsPosition")
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public ResponseData apppointsPosition(Long[] ids,String positionNumber ,String storageNumber, String condition ) {
        boolean bbb=verification(storageNumber ,condition,positionNumber);
        if(bbb){
            List<StoragePutSingle> ulist =  new ArrayList<StoragePutSingle>();
            for (Long id :ids) {
                StoragePutSingle storagePutSingle = storagePutSingleService.getById(id);
                storagePutSingle.setPositionNumber(positionNumber);
        		ulist.add(storagePutSingle);
            }
            storagePutSingleService.updateBatchList(ulist);
            return ResponseData.success();

        }
        ResponseData responsedata = new ResponseData();
        responsedata.setSuccess(false);
        return responsedata;
    }

    public boolean verification(String storageNumber,String condition,String positionNumber){
        BasicPositionParam basicPositionParam = new BasicPositionParam();
        User user = userService.getcurrentUser();

        basicPositionParam.setDeliverId(user.getDeliverId());//通过交付id查询库位
        Long deptId = user.getDeptId();//获取部门id
        StoragePutParam sParam = new StoragePutParam();
        sParam.setStorageNumber(storageNumber);
        StoragePutResult sResult = storagePutService.findBySpec(sParam);
        List<BasicPositionResult> a= basicPositionService.findListBySpec(basicPositionParam,condition,deptId,sResult.getWarehouseId(),user.getOperateId());
        if(a.isEmpty()){
            return false;
        }else {
            for(int i=0;i<a.size(); i++){
                 String u=a.get(i).getPositionNumber();
                if(positionNumber.equals(u)){
                    return true;
                }
            }
            return false;
        }
    }

    /**
     * 查看详情接口
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(StoragePutSingleParam storagePutSingleParam) {
        StoragePutSingle detail = this.storagePutSingleService.getById(storagePutSingleParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(StoragePutSingleParam storagePutSingleParam,String condition ) {
    	storagePutSingleParam.setSingleState("NOT_STARTED");
        return this.storagePutSingleService.findPageBySpec(storagePutSingleParam,condition);
    }

    /**
     * 查询明细
     * 入库单查询
     */
    @ResponseBody
    @RequestMapping("/querylist")
    public LayuiPageInfo querylist(StoragePutSingleParam storagePutSingleParam,String condition ) {
        return this.storagePutSingleService.findPageBySpec(storagePutSingleParam,condition);
    }

    /**
     * app仓管查询托盘列表
     */
    @ResponseBody
    @RequestMapping("/applist")
    public List<StoragePutSingleResult> applist(StoragePutSingleParam storagePutSingleParam) {
        storagePutSingleParam.setSingleState("NOT_STARTED");
        return this.storagePutSingleService.customList(storagePutSingleParam);
    }

    /**
     * app工人查询托盘列表
     */
    @ResponseBody
    @RequestMapping("/applistwork")
    public List<StoragePutSingleResult> applistwork(StoragePutSingleParam storagePutSingleParam) {
        storagePutSingleParam.setSingleState("NOT_RECEIVED");
        return this.storagePutSingleService.TcustomList(storagePutSingleParam);
    }

    /**
     * 查询商品列表
     */
    @ResponseBody
    @RequestMapping("/listgoods")
    public LayuiPageInfo listgoods(StoragePutSingleParam storagePutSingleParam) {
    	storagePutSingleParam.setSingleState("webstorage");
        return this.storagePutSingleService.findPageDISTINCTGoods(storagePutSingleParam);
    }

    /**
     * app查询商品列表
     */
    @ResponseBody
    @RequestMapping("/applistgoods")
    public LayuiPageInfo applistgoods(StoragePutSingleParam storagePutSingleParam) {
        storagePutSingleParam.setSingleState("webstorage");
        return this.storagePutSingleService.findPageDISTINCTGoods(storagePutSingleParam);
    }

    /**
     * app查询入库工作单商品列表
     */
    @ResponseBody
    @RequestMapping("/applistgoodswork")
    public LayuiPageInfo applistgoodswork(StoragePutSingleParam storagePutSingleParam) {
        storagePutSingleParam.setSingleState("webstorage");
        return this.storagePutSingleService.findPageworkGoods(storagePutSingleParam);
    }

    /**
     * 查询批次列表
     * @author zhucx
     * @Date 2019-07-08
     */
    @ResponseBody
    @RequestMapping("/listbatch")
    public LayuiPageInfo listbatch(StoragePutSingleParam storagePutSingleParam) {
    	storagePutSingleParam.setSingleState("webstorage");
        return this.storagePutSingleService.findPageDISTINCTbatch(storagePutSingleParam);
    }

    /**
     * app查询批次列表
     * app入库推荐库位（    ~ ..  ~  ）***
     */
    @RequestMapping(value="/applistbatch",method = {RequestMethod.POST})
    @ResponseBody
    public LayuiPageInfo applistbatch(StoragePutSingleParam storagePutSingleParam) {
    	User user = userService.getcurrentUser();
        storagePutSingleParam.setSingleState("appstorageDistribution");
        try {
            storagePutSingleService.allotPosition(storagePutSingleParam,user);
        } catch (Exception e) {
        }
        return this.storagePutSingleService.findPageDISTINCTbatch(storagePutSingleParam);
    }

    /**
     * app查询入库工作单批次列表
     */
    @ResponseBody
    @RequestMapping("/applistbatchwork")
    public LayuiPageInfo applistbatchwork(StoragePutSingleParam storagePutSingleParam) {
        storagePutSingleParam.setSingleState("appstorage");
        LayuiPageInfo layuiPageInfo=this.storagePutSingleService.findPageDISTINCTbatch(storagePutSingleParam);
        return layuiPageInfo;
    }

    /**
     * 查询库位列表
     */
    @ResponseBody
    @RequestMapping("/positionList")
    public LayuiPageInfo positionList(BasicPositionParam basicPositionParam,String condition,String storageNumber ) {
    	User user = userService.getcurrentUser();
    	basicPositionParam.setDeliverId(user.getDeliverId());
    	Long deptId = user.getDeptId();
    	StoragePutParam sParam = new StoragePutParam();
    	sParam.setStorageNumber(storageNumber);
    	StoragePutResult sResult = storagePutService.findBySpec(sParam);
        LayuiPageInfo layuipageinfo = this.basicPositionService.findPageBySpec(basicPositionParam,condition,deptId,sResult.getWarehouseId(),user.getOperateId());
        return layuipageinfo;
    }

    /**
     * 查询库位列表
     */
    @ResponseBody
    @RequestMapping("/pointsPositionzz")
    public LayuiPageInfo pointsPositionzz(BasicPositionParam basicPositionParam,String condition,String storageNumber ) {
    	User user = userService.getcurrentUser();
    	basicPositionParam.setDeliverId(user.getDeliverId());
    	Long deptId = user.getDeptId();
    	StoragePutParam sParam = new StoragePutParam();
    	sParam.setStorageNumber(storageNumber);
    	StoragePutResult sResult = storagePutService.findBySpec(sParam);
        LayuiPageInfo layuipageinfo = this.basicPositionService.findPageBySpec(basicPositionParam,condition,deptId,sResult.getWarehouseId(),user.getOperateId());
        return layuipageinfo;
    }

    /**
     * 库存监控查询库位列表
     */
    @ResponseBody
    @RequestMapping("/stockPositionList")
    public LayuiPageInfo stockPositionList(BasicPositionParam basicPositionParam,String condition,Long positionAreaId,Long warehouseId ) {
    	User user = userService.getcurrentUser();
    	basicPositionParam.setDeliverId(user.getDeliverId());
    	if (positionAreaId!=null) {
    		basicPositionParam.setPositionAreaId(Integer.parseInt(positionAreaId.toString()));
		}
    	Long deptId = user.getDeptId();
        return this.basicPositionService.findPageBySpec(basicPositionParam,condition,deptId,warehouseId,user.getOperateId());
    }



}


